-- open_grid_reduce
-- created by xinj
-- 中毒

return {
    apply = function(prop, baseValue)
        return baseValue - prop[3];
    end,

    -- 每回合触发
    trigger = function(who, prop, arg)     
        if who.type ~= OBJECT_TYPE_MONSTER then
            return 0;
        end

        if type(arg) ~= "number" then
            return 0;
        end

        -- 有值才计算
        if prop[3] <= 0 then
            return arg;
        end

        local openGrid = 0;
        -- 统计开过的格子
        for p = 1, DUNGEON_WIDTH * DUNGEON_HEIGHT do
            local grid = DungeonM.getGridByPos(p);

            if grid:isOpened() then
                openGrid = openGrid + 1;
            end
        end

        local value = math.max(0, arg - openGrid * prop[3]);
        return value;
    end,

    record = function(target, prop, path)
        return false;
    end 
};